
package com.huaweicloud.haydn.delivercore.agent.dto;

import lombok.Data;

@Data
public class CommonResult<T> {
    public static final String SUCCESS_CODE = "HAYDN.10000000";

    public static final String SUCCESS_MSG = "OK";

    private String code = SUCCESS_CODE;

    private String message = SUCCESS_MSG;

    private T data = null;

    private long timestamp = System.currentTimeMillis();

    public CommonResult() {

    }

    public CommonResult(T data) {
        this.data = data;
    }

    public CommonResult(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public void setError(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static <T> CommonResult<T> success(T data) {
        CommonResult<T> commonResult = new CommonResult<>(data);
        commonResult.setCode(SUCCESS_CODE);
        commonResult.setMessage(SUCCESS_MSG);
        commonResult.setData(data);
        return commonResult;
    }
}
